package com.neo.springboot.controller;

import java.util.Locale;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

	@Value(value="${book.author}")
	private String author;

	@Value(value="${book.name}")
	private String name;
	
	@RequestMapping("/hello")
	public String hello(Locale locale, Model model){
		System.out.println(locale.getCountry());
		return "hello world! 我推荐你读，" + author + "的《" + name + "》";
	}
	
	@RequestMapping("/uid")
	public String uid(HttpSession session){
		UUID uid = (UUID)session.getAttribute("uid");
		if(uid == null){
			uid = UUID.randomUUID();
		}
		System.out.println(uid);
		session.setAttribute("uid", uid);
		
		return session.getId();
	}
}
